﻿Imports System.Threading
Imports System.Web
Imports Sy.Data
Imports Sy.UI.Common
Imports Sy.UI
Imports System.Text
Imports ZXing
Imports ZXing.Common
Imports System.ComponentModel

Public Class Frm_tools
    'Public Skin As Skin
    Dim trans As Thread
    Dim checkean As Thread
    Dim alltext As String
    Dim thislan As String
    Dim allcode As String

    Private writer As BarcodeWriter = New BarcodeWriter


    Private Sub Frm_tools_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try
            Dim Create = CreateSQLBuilder(Of TaskList5).CreateSQL()
            DB = New SQLite(Create, Application.StartupPath & "\Config\task5.db")
            TaskList5.AddDB(DB)
            DB.Foreign_keys = True
            UIAdapter.ListviewAdapter(Of TaskList5)(ListView2, "序号")
            Dim Create4 = CreateSQLBuilder(Of TaskList4).CreateSQL()
            DB4 = New SQLite(Create4, Application.StartupPath & "\Config\task4.db")
            TaskList4.AddDB(DB4)
            DB4.Foreign_keys = True
            UIAdapter.ListviewAdapter(Of TaskList4)(ListView1, "序号")
            loadlan(source, 0)
            loadlan(outlan, 1)
            Loadlist("", ListView1)
            Loadlist("", ListView2)
            codetype.Items.Add("EAN")
            codetype.Items.Add("UPC")
            codetype.SelectedIndex = 0
            ComboBox3.Items.Add("EAN")
            ComboBox3.Items.Add("UPC")
            ComboBox3.SelectedIndex = 0
            qima.Items.Add("1")
            qima.Items.Add("6")
            qima.Items.Add("7")
            qima.Items.Add("8")
            qima.Items.Add("9")
            qima.SelectedIndex = 0
            country.Items.Add("中国")
            country.Items.Add("中国香港")
            country.Items.Add("中国台湾")
            country.Items.Add("中国澳门")
            country.Items.Add("美国")
            country.Items.Add("加拿大")
            country.Items.Add("墨西哥")
            country.Items.Add("英国")
            country.Items.Add("法国")
            country.Items.Add("德国")
            country.Items.Add("意大利")
            country.Items.Add("西班牙")
            country.Items.Add("荷兰")
            country.Items.Add("瑞典")
            country.Items.Add("波兰")
            country.Items.Add("沙特阿拉伯")
            country.Items.Add("阿联酋")
            country.Items.Add("日本")
            country.Items.Add("澳大利亚")
            country.Items.Add("新加坡")
            country.Items.Add("印度")
            country.SelectedIndex = 0
            TabControl1.TabPages(2).Parent = Nothing
            Try
                Dim url = "https://www.miwaimao.com/api/freetool.php"
                Dim html = Sy.Net.Factory.Http(url).Get()
                Dim canshu = Split(html, "||")
                picurl = canshu(0)
                jumpurl = canshu(1)
                picurl2 = canshu(2)
                PictureBox1.Load(picurl)
                PictureBox2.Load(picurl2)
            Catch ex As Exception

            End Try
        Catch ex As Exception
            MsgBox("载入出错!")
        End Try
    End Sub
    Sub Loadlist(sqlstr As String, listv As ListView)
        Try
            With listv
                .Items.Clear()
            End With
            Dim TaskLists
            If listv.Name = "ListView1" Then
                TaskLists = If(sqlstr.IsNotWhiteSpace, TaskList4.LoadWhere(sqlstr), TaskList4.Load())
            End If
            If listv.Name = "ListView2" Then
                TaskLists = If(sqlstr.IsNotWhiteSpace, TaskList5.LoadWhere(sqlstr), TaskList5.Load())
            End If
            Dim i As Long = 1
            For Each tasklist In TaskLists
                Dim a = UIAdapter.GetListViewItem(tasklist, i)
                Dim itm As ListViewItem = listv.Items.Add(a) '状态 进度 id
                itm.Tag = tasklist
                i = i + 1
            Next
        Catch ex As Exception
            MsgBox("加载数据异常", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub
    Sub loadlan(opt As ComboBox, index As Integer)
        opt.Items.Add("简体中文")
        opt.Items.Add("英语")
        opt.Items.Add("法语")
        opt.Items.Add("德语")
        opt.Items.Add("西班牙语")
        opt.Items.Add("意大利语")
        opt.Items.Add("波兰语")
        opt.Items.Add("挪威语")
        opt.Items.Add("丹麦语")
        opt.Items.Add("瑞典语")
        opt.Items.Add("葡萄牙语")
        opt.Items.Add("荷兰语")
        opt.Items.Add("土耳其语")
        opt.Items.Add("日语")
        opt.Items.Add("韩语")
        opt.Items.Add("印地语")
        opt.Items.Add("马来语")
        opt.Items.Add("泰语")
        opt.Items.Add("越南语")
        opt.Items.Add("印度尼西亚语")
        opt.Items.Add("希伯来语")
        opt.Items.Add("匈牙利语")
        opt.Items.Add("波斯语")
        opt.Items.Add("菲律宾语")
        opt.Items.Add("乌克兰语")
        opt.Items.Add("俄语")
        opt.SelectedIndex = index
    End Sub
    Function getlancode(lan As String)
        Try
            If lan = "简体中文" Then Return "zh-CN"
            If lan = "英语" Then Return "en"
            If lan = "法语" Then Return "fr"
            If lan = "德语" Then Return "de"
            If lan = "西班牙语" Then Return "es"
            If lan = "意大利语" Then Return "it"
            If lan = "波兰语" Then Return "pl"
            If lan = "挪威语" Then Return "no"
            If lan = "丹麦语" Then Return "da"
            If lan = "瑞典语" Then Return "sv"
            If lan = "葡萄牙语" Then Return "pt"
            If lan = "荷兰语" Then Return "nl"
            If lan = "土耳其语" Then Return "tr"
            If lan = "日语" Then Return "ja"
            If lan = "韩语" Then Return "ko"
            If lan = "印地语" Then Return "hi"
            If lan = "马来语" Then Return "ms"
            If lan = "泰语" Then Return "th"
            If lan = "越南语" Then Return "vi"
            If lan = "印度尼西亚语" Then Return "id"
            If lan = "希伯来语" Then Return "he"
            If lan = "匈牙利语" Then Return "hu"
            If lan = "波斯语" Then Return "fa"
            If lan = "菲律宾语" Then Return "tl"
            If lan = "乌克兰语" Then Return "uk"
            If lan = "俄语" Then Return "ru"
        Catch ex As Exception
            Return ""
        End Try
    End Function

    Private Sub Button16_Click(sender As Object, e As EventArgs) Handles btntansstart.Click
        Try
            If Trim(inputtext.Text) = "" Then
                MsgBox("请先输入文本!")
                Exit Sub
            End If
            shuchu.Text = "等待识别中..." & vbCrLf
            alltext = inputtext.Text
            thislan = outlan.Text
            btntansstart.Enabled = False
            trans = New System.Threading.Thread(New System.Threading.ParameterizedThreadStart(AddressOf translate))
            trans.Name = NameOf(translate)
            trans.Start()   '启动线程
            btntansstop.Enabled = True
        Catch ex As Exception
            MsgBox("发生错误!")
            btntansstart.Enabled = True
            btntansstop.Enabled = False
        End Try

    End Sub
    Sub translate()
        Try
            Dim url = "https://aiarticlespinner.co/wp-content/plugins/rewriteplugin/paraphrase.php"
            Dim postdata = Sy.Net.PostDataBuilder
            postdata.Add("level", "best")
            postdata.Add("dest", getlancode(thislan))
            'postdata.Add("text", System.Web.HttpUtility.UrlEncode(alltext))
            postdata.Add("text", alltext)
            Dim html = Sy.Net.Factory.Http(url).SetHeader("x-requested-with", "XMLHttpRequest").SetPostDataBuilder(postdata).Post()
            Dim Obj2 = ClsResult.Deserialize(html)
            Invoke(Sub()
                       shuchu.Text &= "识别成功!" & vbCrLf
                       aitext.Text = Obj2.result
                       btntansstart.Enabled = True
                       btntansstop.Enabled = False
                   End Sub)
        Catch ex As Exception
            MsgBox("发生错误,请重试!")
            Invoke(Sub()
                       btntansstart.Enabled = True
                       btntansstop.Enabled = False
                   End Sub)
        End Try
    End Sub

    Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
        Clipboard.Clear()
        Clipboard.SetText(aitext.Text)
        MsgBox("复制成功!")
    End Sub

    Private Sub btntansstop_Click(sender As Object, e As EventArgs) Handles btntansstop.Click
        Try
            If trans.IsAlive Then
                trans.Abort()
            End If
            btntansstart.Enabled = True
            btntansstop.Enabled = False
            shuchu.Text &= "已经停止" & vbCrLf
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles btncheckstart.Click
        Try
            If Trim(codeinput.Text) = "" Then
                MsgBox("请先输入EAN/UPC码!")
                Exit Sub
            End If
            shuchu.Text = "等待检测中..." & vbCrLf
            allcode = codeinput.Text
            btncheckstart.Enabled = False
            checkean = New System.Threading.Thread(New System.Threading.ParameterizedThreadStart(AddressOf checkeancode))
            checkean.Name = NameOf(checkeancode)
            checkean.Start()   '启动线程
            btncheckstop.Enabled = True
        Catch ex As Exception
            MsgBox("发生错误!")
            btncheckstart.Enabled = True
            btncheckstop.Enabled = False
        End Try
    End Sub
    Sub checkeancode()
        Try
            Dim checkcode = Split(allcode, vbCrLf)
            Dim thistype As String = ""
            Dim company_name As String = ""
            For i = 0 To UBound(checkcode)
                If checkcode(i) <> "" Then
                    If Len(checkcode(i)) = 13 Then
                        thistype = "EAN"
                    ElseIf Len(checkcode(i)) = 12 Then
                        thistype = "UPC"
                    Else
                        thistype = "未知"
                    End If
                    Dim url = "https://bff.gds.org.cn/gds/searching-api/ImportProduct/GetImportProductDataForGtin?PageSize=30&PageIndex=1&Gtin=" & checkcode(i) & "&AndOr=1"
                    Dim html = Sy.Net.Factory.Http(url).Get()
                    'Console.WriteLine(html)
                    Dim Obj2 = ImportProduct.DeserializeSafety(html)
                    Try
                        company_name = Obj2.Data.Items(0).realname.ToString
                    Catch ex As Exception
                        company_name = ""
                    End Try
                    Dim t As New TaskList5
                    t.thetype = thistype
                    t.code = checkcode(i)
                    t.company = company_name
                    t.Add()
                    Invoke(Sub()
                               Dim itm As ListViewItem
                               itm = ListView2.Items.Add(ListView2.Items.Count + 1)
                               itm.SubItems.AddRange({CStr(thistype), CStr(checkcode(i)), CStr(company_name)})
                           End Sub)
                    If company_name <> "" Then
                        Invoke(Sub()
                                   shuchu.Text &= checkcode(i) & " 有效" & vbCrLf
                               End Sub)
                    Else
                        Invoke(Sub()
                                   shuchu.Text &= checkcode(i) & " 无效" & vbCrLf
                               End Sub)
                    End If
                    'Console.WriteLine(company_name)
                    Thread.Sleep(2000)
                End If
            Next
            MsgBox("检测完成!")
            Invoke(Sub()
                       Loadlist("", ListView2)
                       shuchu.Text &= "检测完成" & vbCrLf
                       btncheckstart.Enabled = True
                       btncheckstop.Enabled = False
                   End Sub)
        Catch ex As Exception
            MsgBox("发生错误,请重试!")
            Invoke(Sub()
                       btncheckstart.Enabled = True
                       btncheckstop.Enabled = False
                   End Sub)
        End Try
    End Sub

    Private Sub shuchu_TextChanged(sender As Object, e As EventArgs) Handles shuchu.TextChanged
        Try
            If UBound(Split(shuchu.Text, vbCrLf)) > 9 Then
                shuchu.Text = Mid(shuchu.Text, InStr(shuchu.Text, vbCrLf) + 2)
            End If
            shuchu.SelectionStart = Len(shuchu.Text)
            shuchu.ScrollToCaret()
        Catch ex As Exception
            MsgBox("状态输出异常！", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub

    Private Sub btncheckstop_Click(sender As Object, e As EventArgs) Handles btncheckstop.Click
        Try
            If checkean.IsAlive Then
                checkean.Abort()
            End If
            Loadlist("", ListView2)
            btncheckstart.Enabled = True
            btncheckstop.Enabled = False
            shuchu.Text &= "已经停止" & vbCrLf
        Catch ex As Exception

        End Try
    End Sub

    Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
        If CheckBox2.Checked = True Then
            For I = 0 To ListView2.Items.Count - 1
                ListView2.Items(I).Checked = True
            Next
        Else
            For I = 0 To ListView2.Items.Count - 1
                ListView2.Items(I).Checked = False
            Next
        End If
    End Sub

    Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
        Try
            For i = 0 To ListView2.Items.Count - 1
                If ListView2.Items(i).Checked = True Then
                    'DB.Execute("delete from tasklist where ID='" & ListView2.Items(i).SubItems(1).Text & "'")
                    Dim TaskList As TaskList5 = ListView2.Items(i).Tag
                    TaskList.Del()
                End If
            Next
            Call Loadlist("", ListView2)
        Catch ex As Exception
            MsgBox("删除出错", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub

    Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
        Try
            Dim TaskList As TaskList5
            TaskList.Execute("delete from t_TaskList5 where 1=1")
            Loadlist("", ListView2)
        Catch ex As Exception
            MsgBox("删除出错", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub

    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        Try
            Dim str As String = "类型,EAN/UPC,厂商名称" & vbCrLf
            Dim sql As String = "select * from t_TaskList5 where company<>'';"
            Dim reader As Data.Common.DbDataReader = DB(sql)
            Do While reader.Read
                str &= reader("thetype").ToString & "," & reader("code").ToString & ",""" & reader("company").ToString & """" & vbCrLf
            Loop
            reader.Close()
            Dim filename = Format(Now(), "yyyy-MM-dd") & ".csv"
            My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" & filename, str, True, Encoding.Default)
            shuchu.Text &= "导出文件成功：" & Application.StartupPath & "\" & filename
            MsgBox("导出成功，请在程序根目录下查看文件！", MsgBoxStyle.OkOnly, "提示")
        Catch ex As Exception
            MsgBox("导出出错！", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub

    Private Sub codetype_SelectedIndexChanged(sender As Object, e As EventArgs) Handles codetype.SelectedIndexChanged
        If codetype.Text = "UPC" Then
            qima.Visible = True
            country.Visible = False
            countrycode.Visible = False
            companycode.Text = "请输入5位厂商数字"
            goodscode.Text = "请输入5位商品数字"
        Else
            qima.Visible = False
            country.Visible = True
            countrycode.Visible = True
            companycode.Text = "请输入4位厂商数字"
            goodscode.Text = "请输入5位商品数字"
        End If
    End Sub
    Function changecode(str As String)
        If str = "中国" Then Return getnum(690, 699)
        If str = "中国香港" Then Return "489"
        If str = "中国台湾" Then Return "471"
        If str = "中国澳门" Then Return "958"
        If str = "美国" Then Return 0 & getnum(30, 39)
        If str = "加拿大" Then Return getnum(754, 755)
        If str = "墨西哥" Then Return "750"
        If str = "英国" Then Return getnum(500, 509)
        If str = "法国" Then Return getnum(300, 379)
        If str = "德国" Then Return getnum(400, 440)
        If str = "意大利" Then Return getnum(800, 839)
        If str = "西班牙" Then Return getnum(840, 849)
        If str = "荷兰" Then Return getnum(870, 879)
        If str = "瑞典" Then Return getnum(730, 739)
        If str = "波兰" Then Return "590"
        If str = "沙特阿拉伯" Then Return "628"
        If str = "阿联酋" Then Return "629"
        If str = "日本" Then Return getnum(450, 459)
        If str = "澳大利亚" Then Return getnum(930, 939)
        If str = "新加坡" Then Return "888"
        If str = "印度" Then Return "890"
    End Function
    Function getnum(minnum As Integer, maxnum As Integer)
        Dim reds As New Random
        Return reds.Next(minnum, maxnum)
    End Function

    Private Sub country_SelectedIndexChanged(sender As Object, e As EventArgs) Handles country.SelectedIndexChanged
        countrycode.Text = changecode(country.Text)
    End Sub

    Private Sub btnstart_Click(sender As Object, e As EventArgs) Handles btnstart.Click
        Try
            If companycode.Text = "" Or goodscode.Text = "" Then
                MsgBox("请输入完整再开始!")
                Exit Sub
            End If
            If codetype.Text = "UPC" Then
                Dim str = qima.Text & companycode.Text & goodscode.Text
                For r = 1 To num.Value
                    Dim newstr = Val(str) + r
                    Dim js = getupcsum(newstr, True) * 3 + getupcsum(newstr, False)
                    Dim jym = 10 - Val(Strings.Right(js.ToString, 1))
                    If jym = 10 Then
                        jym = 0
                    End If
                    Dim t As New TaskList4
                    t.thetype = codetype.Text
                    t.code = newstr & jym
                    t.Add()

                    Console.WriteLine(newstr & jym)
                Next
            Else
                Dim str As String = countrycode.Text & companycode.Text & goodscode.Text
                For r = 1 To num.Value
                    Dim newstr = Val(str) + r
                    Dim tstr As String
                    If Mid(str, 1, 1) = "0" Then
                        tstr = "0" & newstr.ToString
                    Else
                        tstr = newstr.ToString
                    End If
                    Dim js = geteansum(tstr, False) * 3 + geteansum(tstr, True)
                    Dim jym = 10 - Val(Strings.Right(js.ToString, 1))
                    If jym = 10 Then
                        jym = 0
                    End If
                    Dim t As New TaskList4
                    t.thetype = codetype.Text
                    t.code = tstr & jym
                    t.Add()
                    Console.WriteLine(tstr & jym)
                Next
            End If
            Loadlist("", ListView1)
        Catch ex As Exception

        End Try
    End Sub
    Function getupcsum(num As String, model As Boolean) As Integer
        Try
            Dim result = 0
            If model = True Then
                result = result + Val(Mid(num, 1, 1)) + Val(Mid(num, 3, 1)) + Val(Mid(num, 5, 1)) + Val(Mid(num, 7, 1)) + Val(Mid(num, 9, 1)) + Val(Mid(num, 11, 1))
            Else
                result = result + Val(Mid(num, 2, 1)) + Val(Mid(num, 4, 1)) + Val(Mid(num, 6, 1)) + Val(Mid(num, 8, 1)) + Val(Mid(num, 10, 1))
            End If
            Return result
        Catch ex As Exception
            Return 0
        End Try
    End Function
    Function geteansum(num As String, model As Boolean) As Integer
        Try
            Dim result = 0
            If model = True Then
                result = result + Val(Mid(num, 1, 1)) + Val(Mid(num, 3, 1)) + Val(Mid(num, 5, 1)) + Val(Mid(num, 7, 1)) + Val(Mid(num, 9, 1)) + Val(Mid(num, 11, 1))
            Else
                result = result + Val(Mid(num, 2, 1)) + Val(Mid(num, 4, 1)) + Val(Mid(num, 6, 1)) + Val(Mid(num, 8, 1)) + Val(Mid(num, 10, 1)) + Val(Mid(num, 12, 1))
            End If
            Return result
        Catch ex As Exception
            Return 0
        End Try
    End Function

    Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
        Loadlist("1=1 and thetype='" & ComboBox3.Text & "'", ListView1)
    End Sub

    Private Sub TabPage1_Click(sender As Object, e As EventArgs) Handles TabPage1.Click

    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            For I = 0 To ListView1.Items.Count - 1
                ListView1.Items(I).Checked = True
            Next
        Else
            For I = 0 To ListView1.Items.Count - 1
                ListView1.Items(I).Checked = False
            Next
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Try
            For i = 0 To ListView1.Items.Count - 1
                If ListView1.Items(i).Checked = True Then
                    'DB.Execute("delete from tasklist where ID='" & ListView2.Items(i).SubItems(1).Text & "'")
                    Dim TaskList As TaskList4 = ListView1.Items(i).Tag
                    TaskList.Del()
                End If
            Next
            Call Loadlist("", ListView1)
        Catch ex As Exception
            MsgBox("删除出错", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Try
            Dim TaskList As TaskList4
            TaskList.Execute("delete from t_TaskList4 where 1=1")
            Loadlist("", ListView1)
        Catch ex As Exception
            MsgBox("删除出错", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Try
            Dim str As String = "类型,EAN/UPC" & vbCrLf
            For I = 0 To ListView1.Items.Count - 1
                If ListView1.Items(I).Checked = True Then
                    str &= ListView1.Items(I).SubItems(1).Text & "," & ListView1.Items(I).SubItems(2).Text & vbCrLf
                End If
            Next
            Dim filename = Format(Now(), "yyyy-MM-dd") & ".csv"
            My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" & filename, str, True, Encoding.Default)
            shuchu.Text &= "导出文件成功：" & Application.StartupPath & "\" & filename & vbCrLf
            MsgBox("导出成功，请在程序根目录下查看文件！", MsgBoxStyle.OkOnly, "提示")
        Catch ex As Exception
            MsgBox("导出出错！", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Try
            Dim str As String = "类型,EAN/UPC" & vbCrLf
            Dim sql As String = "select * from t_TaskList4;"
            Dim reader As Data.Common.DbDataReader = DB4(sql)
            Do While reader.Read
                str &= reader("thetype").ToString & "," & reader("code").ToString & vbCrLf
            Loop
            reader.Close()
            Dim filename = Format(Now(), "yyyy-MM-dd") & ".csv"
            My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" & filename, str, True, Encoding.Default)
            shuchu.Text &= "导出文件成功：" & Application.StartupPath & "\" & filename
            MsgBox("导出成功，请在程序根目录下查看文件！", MsgBoxStyle.OkOnly, "提示")
        Catch ex As Exception
            MsgBox("导出出错！", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub

    Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
        Try
            OpenFileDialog1.InitialDirectory = Application.StartupPath
            OpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
            OpenFileDialog1.FilterIndex = 1
            If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                Dim s = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName, Encoding.Default)
                Dim str = Split(s, vbCrLf)
                For i = 0 To UBound(str)
                    Dim stype As String = ""
                    If Trim(str(i)) <> "" Then
                        If str(i).Length = 12 Then
                            stype = "UPC"
                        ElseIf str(i).Length = 13 Then
                            stype = "EAN"
                        Else
                            stype = "未知"
                        End If
                        Dim t As New TaskList4
                        t.thetype = stype
                        t.code = Trim(str(i))
                        t.Add()
                    End If
                Next
                Loadlist("", ListView1)
            End If
        Catch ex As Exception
            MsgBox("导入出错！", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        Try
            Process.Start(jumpurl)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Try
            writer.Format = BarcodeFormat.EAN_13
            writer.Options.Height = 50
            writer.Options.Width = 144
            'writer.Renderer = IBarcodeRenderer
            '(IBarcodeRenderer < Bitmap >)Activator.CreateInstance(Renderer)
            For i = 0 To ListView1.Items.Count - 1
                If ListView1.Items(i).Checked = True Then
                    Dim ntype = ListView1.Items(i).SubItems(1).Text
                    Dim ncode = ListView1.Items(i).SubItems(2).Text
                    If ntype = "EAN" Then
                        writer.Format = BarcodeFormat.EAN_13
                    Else
                        writer.Format = BarcodeFormat.UPC_A
                    End If
                    Dim Str_Path = Application.StartupPath & "\outcode\" & ntype
                    If System.IO.Directory.Exists(Str_Path) Then
                        Dim Bmp As Drawing.Bitmap = writer.Write(ncode)
                        Bmp.Save(Str_Path & "\" & ncode & ".png")
                        Bmp.Dispose()
                        shuchu.Text &= "生成" & ncode & " 成功" & vbCrLf
                    Else
                        shuchu.Text &= "生成" & ncode & " 失败" & vbCrLf
                    End If
                End If
                Thread.Sleep(500)
            Next
            shuchu.Text &= "生成完成" & vbCrLf
            MsgBox("生成完成!")
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        Try
            writer.Format = BarcodeFormat.EAN_13
            writer.Options.Height = 50
            writer.Options.Width = 144
            'writer.Renderer = IBarcodeRenderer
            '(IBarcodeRenderer < Bitmap >)Activator.CreateInstance(Renderer)
            Dim sql As String = "select * from t_TaskList4 where 1=1;"
            Dim reader As Data.Common.DbDataReader = DB4(sql)
            Do While reader.Read
                Dim ntype = reader("thetype").ToString
                Dim ncode = reader("code").ToString
                If ntype = "EAN" Then
                    writer.Format = BarcodeFormat.EAN_13
                Else
                    writer.Format = BarcodeFormat.UPC_A
                End If
                Dim Str_Path = Application.StartupPath & "\outcode\" & ntype
                If System.IO.Directory.Exists(Str_Path) Then
                    Dim Bmp As Drawing.Bitmap = writer.Write(ncode)
                    Bmp.Save(Str_Path & "\" & ncode & ".png")
                    Bmp.Dispose()
                    shuchu.Text &= "生成" & ncode & " 成功" & vbCrLf
                Else
                    shuchu.Text &= "生成" & ncode & " 失败" & vbCrLf
                End If
                Thread.Sleep(500)
            Loop
            shuchu.Text &= "生成完成" & vbCrLf
            MsgBox("生成完成!")
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Frm_tools_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
        'Try
        '    Process.Start(jumpurl)
        'Catch ex As Exception

        'End Try
    End Sub
End Class